package com.hitechbangla.fctu.base.weather;

import com.hitechbangla.fctu.base.Location;
import com.hitechbangla.fctu.base.aircraft.Aircraft;
import java.io.Serializable;
import java.util.List;
import resource_builder.GenericTypeBuilder;

/**
 *
 * @author Asus
 */
public class Cloud implements Serializable
{
    private Location location;
    private double dimension;
    private CloudType cloudType;
    private CloudShape cloudShape;
    private Wind wind;
    

    public Cloud(Location location, float dimension, CloudShape cShape, CloudType cType)
    {
	setLocation(location);
	setDimension(dimension);
        cloudType = cType;
        cloudShape = cShape;
    }
    
    /**
     * @return the location
     */
    public Location getLocation() {
	return location;
    }

    /**
     * @param location the location to set
     */
    public void setLocation(Location location) {
	this.location = location;
    }

    /**
     * @return the dimension
     */
    public double getDimension() {
	return dimension;
    }

    /**
     * @param dimension the dimension to set
     */
    public void setDimension(float dimension) {
	this.dimension = dimension;
    }
    
    public static List<Cloud> getAllCloud()
    {
        GenericTypeBuilder<Cloud> genericTypeBuilder = new GenericTypeBuilder<>();
        List<Cloud> listLayerCollection = genericTypeBuilder.readAll("cloud.object");
	return listLayerCollection;
    }
    
    
    public static void main(String a[])
    {
	List<Cloud> listCloud = getAllCloud();
	for(Cloud cloud: listCloud)
	{
	    //System.out.println(cloud.getDimension());
	}
    }
    
    /**
     * @return the wind
     */
    public Wind getWind() {
	return wind;
    }

    /**
     * @param wind the wind to set
     */
    public void setWind(Wind wind) {
	this.wind = wind;
    }

    
    public static boolean isAircraftWithCloud(Aircraft aircraft)
    {
	List<Cloud> listCloud = getAllCloud();
	 
	//boolean aircraftWithinCloud = false;
	
	for(Cloud cloud: listCloud)
	{
	    double dimension = cloud.getDimension()/2;
	    double xLowerLimit = cloud.getLocation().getX() - dimension;
	    double xUpperLimit = cloud.getLocation().getX() + dimension;
	    
	    double yLowerLimit = cloud.getLocation().getY() - dimension;
	    double yUpperLimit = cloud.getLocation().getY() + dimension;
	    
	    double zLowerLimit = cloud.getLocation().getZ() - dimension;
	    double zUpperLimit = cloud.getLocation().getZ() + dimension;
	    
	    double aircraftX = aircraft.getAircraftState().getLocation().getX();
	    double aircraftY = aircraft.getAircraftState().getLocation().getY();
	    double aircraftZ = aircraft.getAircraftState().getLocation().getZ();
	    
	    if(aircraftX>xLowerLimit && aircraftX<xUpperLimit && aircraftY>yLowerLimit && aircraftY<yUpperLimit && aircraftZ>zLowerLimit && aircraftZ<zUpperLimit)
	    {
		return true;
	    }	    
	}
	
	return false;
    }
}
